const path = require('path')

//导入生成预览页面的插件，得到一个构造函数
const HtmlWebpackPlugin = require('html-webpack-plugin')
const htmlPlugin = new HtmlWebpackPlugin({ //创建插件的实例对象
    template: './src/index.html', //指定要用到的模板文件
    filename: 'index.html' //指定生成的文件名称，
})
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    //编译模式 development production
    mode: 'development',
    entry: path.join(__dirname, './src/index.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    plugins: [htmlPlugin, new VueLoaderPlugin],
    module: {
        rules: [{
                test: /\.css$/,
                use: ['style-loader', 'css-loader', 'postcss-loader']
            },
            {
                test: /\.less$/,
                use: ['style-loader', 'css-loader', 'less-loader']
            },
            {
                test: /\.scss$/,
                use: ['style-loader', 'css-loader', 'sass-loader']
            },
            {
                test: /\.jpg|png|gif|bmp|ttf|eot|svg|woff|wpff2$/,
                use: 'url-loader?limit=16940' //?后是参数项，limit指图片大小，小于limit大小的图片，才会被转化为 base64 图片
            },
            {
                test: /\.js$/,
                use: 'babel-loader',
                exclude: /node_modules/ //exclude为排除项
            },
            {
                test: /\.vue$/,
                loader: 'vue-loader'
            }

        ]
    }
}